﻿using PetaPoco;

namespace BlazorAdmin.Extensions
{
    /// <summary>
    /// PetaPoco 批量删除扩展操作类
    /// </summary>
    public static class IDatabaseDeleteBatchExtensions
    {
        /// <summary>
        /// 批量插入数据库
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="db"></param>
        /// <param name="pocos"></param>
        public static void DeleteBatch<T>(this IDatabase db, IEnumerable<T> pocos)
        {
            if (pocos.Any())
            {
                BatchProvider.Create(db).DeleteBatch(pocos);
            }
        }

        /// <summary>
        /// 批量删除指定表数据
        /// </summary>
        /// <param name="db"></param>
        /// <param name="tableName"></param>
        /// <param name="pocos"></param>
        public static void DeleteBatch(this IDatabase db, string tableName, IEnumerable<object> pocos)
        {
            db.DeleteBatch(tableName, "", pocos);
        }

        /// <summary>
        /// 批量删除指定表数据
        /// </summary>
        /// <param name="db"></param>
        /// <param name="tableName"></param>
        /// <param name="primaryKeyName"></param>
        /// <param name="pocos"></param>
        public static void DeleteBatch(this IDatabase db, string tableName, string primaryKeyName, IEnumerable<object> pocos)
        {
            if (pocos.Any())
            {
                BatchProvider.Create(db).DeleteBatch(tableName, primaryKeyName, pocos);
            }
        }
    }
}
